var userExchange = function(){
    var html = '<div style="margin: 10px">\n' +
        '<div style="margin-top: 10px;margin-right: 20px">\n' +
        '    <form class="layui-form" action="javascript:;" id="selectStockForm">\n' +
        '        <div class="layui-form-item">\n' +
        '            <div class="layui-inline">\n' +
        '                <label class="layui-form-label">用户帐号</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <input type="text" name="id" id="account" autocomplete="off" placeholder="请输入用户帐号"\n' +
        '                           class="layui-input">\n' +
        '                </div>\n' +
        '            </div>\n' +
        '                <div class="layui-inline">\n' +
        '                    <label class="layui-form-label">起始时间</label>\n' +
        '                    <div class="layui-input-inline">\n' +
        '                        <input type="text" name="beginDate" id="date1" lay-verify="datetime" placeholder="起始时间"\n' +
        '                               autocomplete="off" class="layui-input">\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '                <div class="layui-inline">\n' +
        '                    <label class="layui-form-label">截至时间</label>\n' +
        '                    <div class="layui-input-inline">\n' +
        '                        <input type="text" name="endDate" id="date2" lay-verify="datetime" placeholder="结束时间"\n' +
        '                               autocomplete="off" class="layui-input">\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '                <div class="layui-inline">\n' +
        '                    <label class="layui-form-label">状态</label>\n' +
        '                    <div class="layui-input-inline">\n' +
        '                        <select id="status" name="status">' +
            '                        <option value=""></option>\n' +
            '                        <option value="0">审核中</option>\n' +
            '                        <option value="1">通过</option>\n' +
            '                        <option value="2">驳回</option>\n' +
        '                       </select>\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '                <div class="layui-inline">\n' +
        '                    <div class="layui-input-block">\n' +
        '                        <button class="layui-btn" lay-submit="" lay-filter="demo2">立即搜索</button>\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '    </form>\n' +
        '</div>\n' +
        '    <hr style="margin-bottom: 20px">\n' +
        '    <div style="margin-left: 10px;margin-right: 10px">\n' +
        '        <table class="layui-hide" id="demo" lay-filter="test"></table>\n' +
        '    </div>\n' +
        '    <input id="addProductHidden" value="" hidden="hidden">\n' +
        '</div>';
    layui.use(['table', 'form', 'jquery', 'element','layer', 'laydate'], function () {
        var table = layui.table
            ,layer = layui.layer
            , form = layui.form
            , $ = layui.jquery
            , laydate = layui.laydate
            , element = layui.element;
        $("#mainbody").html(html);
        //日期
        laydate.render({
            elem: '#date1'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#date2'
            , type: 'datetime'
        });
        form.render();

        var tableRender = function () {
            //执行一个 table 实例

            table.render({
                elem: '#demo'
                // , height: 420
                , id:"exchangeList"
                , url: '/turnover/userExchange' //数据接口
                , title: '用户提现表'
                , page: true //开启分页
                , toolbar: 'default'
                , limit: 10
                , limits: [10, 20, 30]
                , cols: [[ //表头
                    {type: 'checkbox'}
                    ,{type: 'numbers',title: '序号',width: 80}
                    , {field: 'orderId', align: 'center', title: '订单号', width: 200}
                    , {field: 'userId', align: 'center', title: '用户ID', width: 130}
                    , {field: 'exchangeNum', align: 'center', title: '提现金额', width: 130}
                    , {field: 'bankUser', align: 'center', title: '持卡人', width: 130}
                    , {field: 'bank', align: 'center', title: '银行', width: 130}
                    , {field: 'bankAccount', align: 'center', title: '银行账号', width: 350}
                    , {field: 'time', align: 'center', title: '提现时间', width: 180}
                    ,{
                        filed: "doSth", align: "center", width: 280, title: "操作", templet: function (data) {
                            var str = '';
                            if (data.status == 0) {
                                str += '<span hidden="hidden">'+data.id+'</span><a class="layui-btn layui-btn-primary layui-btn-sm pass" style="background-color: #009688;color: white">同意</a>';
                                str += '<span hidden="hidden">'+data.id+'</span><a class="layui-btn layui-btn-primary layui-btn-sm layui-btn-danger refuse" style="color:white;">拒绝</a>';
                                return str;
                            } else {
                                if (data.status == 1){
                                    return "通过"
                                } else {
                                    return "驳回"
                                }
                            }
                        }
                    },
                ]]
            });
        }

        //初始化表格
        tableRender();

        form.on('submit(demo2)', function (data) {
            var status = data.field.productStatus;
            //layer.msg(data);
            var id = $("#account").val();
            var begin = $("#date1").val();
            var end = $("#date2").val();
            var status = $("#status").val();
            table.reload('exchangeList', {
                where: {"id": id, "status":status,"beginStr": begin, "endStr": end}
            });
        });

        $(document).off('click', '.pass').on('click', '.pass', function (data) {
            var id = $(this).parent().find("span").html();
            var str = $(this).html();
            layer.confirm('确定通过吗？', {icon: 3, title:'提示'}, function(index){
                var data={
                    id:id,
                    status:1
                }
                $.ajax({
                    type: "POST",
                    url: "/turnover/update",
                    traditional: true,
                    data: JSON.stringify(data),
                    // dataType: "json",
                    contentType: "application/json",
                    success: function (data) {
                        if (data=="noUser"){
                            window.location.href("/");
                        }
                        layer.msg('通过成功！', {
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        table.reload("exchangeList");
                    },
                    error: function () {
                        layer.msg("未知错误,请重试!");
                        console.log("调用更新方法失败！");
                    }
                });
            });
        });

        $(document).off('click', '.refuse').on('click', '.refuse', function (data) {
            var id = $(this).parent().find("span").html();
            var str = $(this).html();
            layer.confirm('确定驳回吗？', {icon: 3, title:'提示'}, function(index){
                var data={
                    id:id,
                    status:2
                }
                $.ajax({
                    type: "POST",
                    url: "/turnover/update",
                    traditional: true,
                    data: JSON.stringify(data),
                    // dataType: "json",
                    contentType: "application/json",
                    success: function (data) {
                        if (data=="noUser"){
                            window.location.href("/");
                        }
                        //得到弹出层的index关闭
                        layer.msg('驳回成功！', {
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        table.reload("exchangeList");
                    },
                    error: function () {
                        layer.msg("未知错误,请重试!");
                        console.log("调用更新方法失败！");
                    }
                });
            });
        });



        /*


                //监听指定开关
                form.on('switch(test1)', function (obj) {
                    //开关颜色变红
                    $(obj.othis).css("border-color","red");
                    $(obj.othis).css("background-color","red");
                });


                //监听搜索按钮
                form.on('submit(demo2)', function (data) {
                    var status = data.field.productStatus;
                    //layer.msg(data);
                    var keyword = $("#keyword").val();
                    var productNumber = $("#productNumber").val();
                    var begin = $("#date1").val();
                    var end = $("#date2").val();
                    table.reload('productList', {
                        where: {"keyword": keyword, "beginStr": begin, "endStr": end, "productStatus": status, "productNumber": productNumber}
                    });
                });

            })*/
    })
}